<!DOCTYPE html>
<!--[if IEMobile 7]><html class="iem7" lang="zh-hans" dir="ltr"><![endif]-->
<!--[if (lte IE 6)&(!IEMobile)]><html class="ie6 ie6-7 ie6-8" lang="zh-hans" dir="ltr"><![endif]-->
<!--[if (IE 7)&(!IEMobile)]><html class="ie7 ie6-7 ie6-8" lang="zh-hans" dir="ltr"><![endif]-->
<!--[if (IE 8)&(!IEMobile)]><html class="ie8 ie6-8" lang="zh-hans" dir="ltr"><![endif]-->
<!--[if (gte IE 9)|(gt IEMobile 7)]><!-->
<html class="ie9up ie9 js" dir="ltr" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/terms/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" lang="zh-hans"><!--<![endif]--><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">
<meta charset="utf-8">
<link rel="shortlink" href="http://software.intel.com/zh-cn/node/392764">
<link rel="shortcut icon" href="http://software.intel.com/sites/all/themes/isn3/favicon.ico" type="image/vnd.microsoft.icon">
<link rel="canonical" href="http://software.intel.com/zh-cn/blogs/2013/05/20/java-socket">
<meta name="generator" content="Drupal 7 (http://drupal.org)">
<meta content="java socket 多线程网络传输多个文件" about="/zh-cn/blogs/2013/05/20/java-socket" property="dc:title">
<meta about="/zh-cn/blogs/2013/05/20/java-socket" property="sioc:num_replies" content="0" datatype="xsd:integer">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="MobileOptimized" content="width">
<meta name="HandheldFriendly" content="true">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="cleartype" content="on">
<title>java socket 多线程网络传输多个文件 | Intel® Developer Zone</title>

<link type="text/css" rel="stylesheet" href="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/css_pbm0lsQQJ7A7WCCIMgxLho6mI_kBNgznNUWmTWcnfoE.css" media="all">
<link type="text/css" rel="stylesheet" href="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/css_NXm6PAmqG3dIT0i2TsV13C9qPqDnwe-CMqut-tcDrFY.css" media="all">
<link type="text/css" rel="stylesheet" href="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/css_3mkWh8pRvzprDcFELrqrKGvrqCFc7UXkWwcyEyoiJFI.css" media="all">
<link type="text/css" rel="stylesheet" href="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/css_v6zdewNaLWwjsIV0yOpayORdcqtOKplLmT2JLXqyuDs.css" media="all">
<link type="text/css" rel="stylesheet" href="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/css_s8ByoYYJr6n9zCkxizXPZybiw3SGvvZLBB86rhUi7bQ.css" media="all">
<link type="text/css" rel="stylesheet" href="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/css_5_EBsvYf_U3gqgv1Idal1sImw7zcXB1kaIR6NOugp8o.css" media="print">
<link type="text/css" rel="stylesheet" href="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/css_Lk0i1Rq49zhZknClrYE-0k13DwR38sFSx-F2mXUQfI4.css" media="all">

<!--[if IE]>
<link type="text/css" rel="stylesheet" href="http://software.intel.com/sites/all/themes/isn3/css/ie/ie.less.css?mpmzok" media="all" />
<![endif]-->

<!--[if lte IE 8]>
<link type="text/css" rel="stylesheet" href="http://software.intel.com/sites/all/themes/isn3/css/ie/ie-lte-8.less.css?mpmzok" media="all" />
<![endif]-->

<!--[if lte IE 9]>
<link type="text/css" rel="stylesheet" href="http://software.intel.com/sites/all/themes/isn3/css/ie/ie-lte-9.less.css?mpmzok" media="all" />
<![endif]-->

<!--[if IE 8]>
<link type="text/css" rel="stylesheet" href="http://software.intel.com/sites/all/themes/isn3/css/ie/ie-8.less.css?mpmzok" media="all" />
<![endif]-->

<!--[if IE 9]>
<link type="text/css" rel="stylesheet" href="http://software.intel.com/sites/all/themes/isn3/css/ie/ie-9.less.css?mpmzok" media="all" />
<![endif]-->
<script id="undefined" src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/inpage_linkid.js" async="" type="text/javascript"></script><script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/ga.js" async="" type="text/javascript"></script><script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/jquery.js"></script>
<script>window.jQuery || document.write("<script src='/sites/all/modules/contrib/jquery_update/replace/jquery/1.8/jquery.js'>\x3C/script>")</script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/js_IkgOrrVZK1UTp2HktvFi5vo1g7b25Muyr5GoySikuic.js"></script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/jquery-ui.js"></script>
<script>window.jQuery.ui || document.write("<script src='/sites/all/modules/contrib/jquery_update/replace/ui/ui/jquery-ui.js'>\x3C/script>")</script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/js_DMwnfe9QiEo_dTwKN3_Xn0sTm6SaIfHcnap47maQopY.js"></script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/js_8XA44OgHqVZ85TZB2rCfTeHrKhrbwdyd1k7WFjYaC4E.js"></script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/js_LgJVWMAdXXr5wYLaXleoryijU0JGcTPPW-XxuKVUKcU.js"></script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/BrightcoveExperiences.js"></script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/js_14nXD_jTQ0UXKp3qJlHsPwPPoPk0NU01jqoGSlD2wm8.js"></script>
<script>var _gaq = _gaq || [];_gaq.push(["_setAccount", "UA-17890616-1"]);var pluginUrl = 
 '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(["_setDomainName", ".intel.com"]);
_gaq.push(["_setAllowLinker", true]);_gaq.push(['_setCustomVar', 1, "locale-code", "zh-hans", 3]);_gaq.push(['_setCustomVar', 2, "content", "Blog post|Technical Article||", 3]);_gaq.push(['_setCustomVar', 3, "content-aud", "Developers|Cloud Computing|", 3]);_gaq.push(['_setCustomVar', 4, "content-meta", "||HTML5, Java*, JavaScript*, Python*", 3]);_gaq.push(['_setCustomVar', 5, "member", "f888b2f6-b8c4-1bc4-a56f-ee42e01f1a9d|||", 3]);_gaq.push(["_trackPageview"]);(function() {var ga = document.createElement("script");ga.type = "text/javascript";ga.async = true;ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(ga, s);})();</script>
<script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/js_tEiKIjUYnAnJXA6x8psh1RBUIcw5jwR4im2aF7bXE9Y.js"></script>
<script>jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"zh-cn\/","ajaxPageState":{"theme":"isn3","theme_token":"NMTB-f8-rTuAA44StrxU-SaLCh54HRb0JEPA3FxyBfo","js":{"sites\/all\/modules\/contrib\/block_refresh\/js\/block_refresh.js":1,"sites\/all\/modules\/contrib\/chosen\/chosen.js":1,"sites\/all\/themes\/isn3\/js\/google-track.min.js":1,"sites\/all\/themes\/isn3\/js\/widgets\/jcarousel_fix.min.js":1,"sites\/all\/themes\/isn3\/js\/plupload.min.js":1,"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.8.2\/jquery.js":1,"0":1,"misc\/jquery.once.js":1,"misc\/drupal.js":1,"https:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.10.2\/jquery-ui.js":1,"1":1,"sites\/all\/modules\/custom\/idz_search\/js\/ui\/jquery.ui.selectmenu.js":1,"sites\/all\/modules\/contrib\/jquery_update\/replace\/ui\/external\/jquery.cookie.js":1,"sites\/all\/modules\/custom\/social_block\/social-block.min.js":1,"public:\/\/languages\/zh-hans_mF1LIYtfkirQAp0b0q56WXNbCLk1V8rxInKXOznDmFg.js":1,"http:\/\/admin.brightcove.com\/js\/BrightcoveExperiences.js":1,"sites\/all\/libraries\/chosen\/chosen\/chosen.jquery.min.js":1,"sites\/all\/libraries\/colorbox\/colorbox\/jquery.colorbox-min.js":1,"sites\/all\/modules\/contrib\/colorbox\/js\/colorbox.js":1,"sites\/all\/modules\/contrib\/colorbox\/js\/colorbox_load.js":1,"sites\/all\/modules\/contrib\/panels\/js\/panels.js":1,"sites\/all\/modules\/contrib\/quote\/quote.js":1,"sites\/all\/modules\/contrib\/views_slideshow\/js\/views_slideshow.js":1,"sites\/all\/modules\/custom\/idz_search\/js\/idz_search_block.js":1,"sites\/all\/modules\/custom\/cmswithtms\/js\/config.js":1,"sites\/all\/modules\/contrib\/google_analytics\/googleanalytics.js":1,"2":1,"sites\/all\/themes\/isn3\/js\/header.min.js":1,"sites\/all\/themes\/isn3\/js\/footer.min.js":1,"sites\/all\/themes\/isn3\/js\/colorbox_alter.min.js":1,"sites\/all\/themes\/isn3\/js\/tabs.min.js":1,"sites\/all\/themes\/isn3\/js\/collapsible.min.js":1,"sites\/all\/themes\/isn3\/js\/bootstrap.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shCore.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushAS3.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushBash.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushColdFusion.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushCpp.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushCSharp.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushCss.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushDelphi.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushDiff.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushErlang.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushFortran.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushGroovy.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushJavaFX.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushJava.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushJScript.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushPerl.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushPhp.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushPlain.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushPowerShell.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushPython.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushR.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushRuby.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushScala.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushSql.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushVb.min.js":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/scripts\/shBrushXml.min.js":1,"sites\/all\/themes\/isn3\/js\/intel_filter.min.js":1},"css":{"modules\/system\/system.base.css":1,"modules\/system\/system.menus.css":1,"modules\/system\/system.messages.css":1,"modules\/system\/system.theme.css":1,"misc\/ui\/jquery.ui.core.css":1,"misc\/ui\/jquery.ui.theme.css":1,"sites\/all\/modules\/custom\/idz_search\/css\/ui\/jquery.ui.selectmenu.css":1,"sites\/all\/modules\/custom\/bds\/bds.css":1,"modules\/book\/book.css":1,"modules\/comment\/comment.css":1,"sites\/all\/modules\/contrib\/date\/date_api\/date.css":1,"sites\/all\/modules\/contrib\/date\/date_popup\/themes\/datepicker.1.7.css":1,"modules\/field\/theme\/field.css":1,"sites\/all\/modules\/contrib\/mollom\/mollom.css":1,"modules\/node\/node.css":1,"sites\/all\/modules\/custom\/node_attachments_block\/node-attachments-block.less.css":1,"modules\/poll\/poll.css":1,"sites\/all\/modules\/custom\/social_block\/social-block.less.css":1,"modules\/user\/user.css":1,"modules\/forum\/forum.css":1,"sites\/all\/modules\/contrib\/views\/css\/views.css":1,"sites\/all\/modules\/custom\/intel_advanced_forum_style\/styles\/idz\/advanced-forum.idz.images.css":1,"sites\/all\/modules\/custom\/intel_advanced_forum_style\/styles\/idz\/advanced-forum.idz.structure.css":1,"sites\/all\/modules\/contrib\/block_refresh\/css\/block_refresh.css":1,"sites\/all\/libraries\/chosen\/chosen\/chosen.css":1,"sites\/all\/modules\/contrib\/chosen\/css\/chosen-drupal.css":1,"sites\/all\/libraries\/colorbox\/example1\/colorbox.css":1,"sites\/all\/modules\/contrib\/ctools\/css\/ctools.css":1,"sites\/all\/modules\/contrib\/oembed\/oembed.base.css":1,"sites\/all\/modules\/contrib\/oembed\/oembed.theme.css":1,"sites\/all\/modules\/contrib\/panels\/css\/panels.css":1,"sites\/all\/modules\/contrib\/quote\/quote.css":1,"sites\/all\/modules\/contrib\/views_slideshow\/views_slideshow.css":1,"modules\/locale\/locale.css":1,"modules\/contextual\/contextual.css":1,"sites\/all\/themes\/adaptivetheme\/adaptivetheme\/css\/at.base.css":1,"sites\/all\/themes\/adaptivetheme\/adaptivetheme\/css\/at.layout.css":1,"sites\/all\/themes\/adaptivetheme\/adaptivetheme\/css\/at.messages.css":1,"sites\/all\/themes\/isn3\/css\/html-elements.css":1,"sites\/all\/themes\/isn3\/css\/fonts.css":1,"sites\/all\/themes\/isn3\/css\/forms.css":1,"sites\/all\/themes\/isn3\/css\/tables.css":1,"sites\/all\/themes\/isn3\/css\/fields.css":1,"sites\/all\/themes\/isn3\/css\/page.less.css":1,"sites\/all\/themes\/isn3\/css\/navigation.less.css":1,"sites\/all\/themes\/isn3\/css\/articles.css":1,"sites\/all\/themes\/isn3\/css\/comments.less.css":1,"sites\/all\/themes\/isn3\/css\/blocks.less.css":1,"sites\/all\/themes\/isn3\/css\/forum-page.less.css":1,"sites\/all\/themes\/isn3\/css\/views.less.css":1,"sites\/all\/themes\/isn3\/css\/bootstrap-idz.less.css":1,"sites\/all\/themes\/isn3\/css\/search.less.css":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/styles\/shCore.css":1,"sites\/all\/themes\/isn3\/js\/syntaxhighlighter\/styles\/shThemeIntel.css":1,"sites\/all\/themes\/isn3\/css\/print.css":1,"sites\/all\/themes\/isn3\/css\/isn3.responsive.style.less.css":1,"sites\/all\/themes\/isn3\/css\/isn3.responsive.gpanels.css":1,"sites\/all\/themes\/isn3\/css\/ie\/ie.less.css":1,"sites\/all\/themes\/isn3\/css\/ie\/ie-lte-8.less.css":1,"sites\/all\/themes\/isn3\/css\/ie\/ie-lte-9.less.css":1,"sites\/all\/themes\/isn3\/css\/ie\/ie-8.less.css":1,"sites\/all\/themes\/isn3\/css\/ie\/ie-9.less.css":1}},"chosen":{"selector":"select","minimum":"10","minimum_width":"200","search_contains":true,"placeholder_text_multiple":"Choose some options","placeholder_text_single":"Choose an option","no_results_text":"No results match"},"colorbox":{"transition":"elastic","speed":"350","opacity":"0.85","slideshow":false,"slideshowAuto":true,"slideshowSpeed":"2500","slideshowStart":"start slideshow","slideshowStop":"stop slideshow","current":"{current} of {total}","previous":"\u00ab Prev","next":"Next \u00bb","close":"","overlayClose":true,"maxWidth":"1280px","maxHeight":"100%","initialWidth":"575","initialHeight":"566","fixed":false,"scrolling":false},"jcarousel":{"ajaxPath":"\/zh-cn\/jcarousel\/ajax\/views"},"quote_nest":"2","googleanalytics":{"trackOutbound":1,"trackMailto":1,"trackDownload":1,"trackDownloadExtensions":"7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|pkg|png|ppt|pptx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip","trackDomainMode":"1"},"isn3":{"language_url":{"language":"zh-hans","name":"Chinese, Simplified","native":"\u7b80\u4f53\u4e2d\u6587","direction":"0","enabled":"1","plurals":"2","formula":"($n!=1)","domain":"","prefix":"zh-cn","weight":"-9","javascript":"mF1LIYtfkirQAp0b0q56WXNbCLk1V8rxInKXOznDmFg","provider":"locale-url"}},"currentTheme":{"name":"isn3","path":"sites\/all\/themes\/isn3"}});</script>

<!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lte IE 7]>
  <script src="/sites/all/themes/isn3/js/legacy_IE_warning.js"></script>
<![endif]-->
<!--[if !IE]><!--><script>if(/*@cc_on!@*/false){document.documentElement.className+=' ie10';}</script><!--<![endif]-->
</head>
<body class="html not-front not-logged-in no-sidebars  i18n-zh-hans site-name-hidden isn3">
  <div id="skip-link">
    <a href="#main-content" class="element-invisible element-focusable">跳转到主要内容</a>
  </div>
    <div id="page" class="container blog  nodeid-392764 intel_filter_syntaxhighlighter-processed">
  <header class="clearfix" role="banner">

          <div id="logo"><a href="http://software.intel.com/zh-cn" title="主页"><img src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/logo.png" alt="Intel® Developer Zone logo"></a></div>
    
          <hgroup class="element-invisible">
                  <h1 id="site-name" class="element-invisible"><a href="http://software.intel.com/zh-cn" title="主页">Intel® Developer Zone</a></h1>
                      </hgroup>
    
      <div class="region region-header">
    <nav id="block-menu-menu-main-menu-2" class="block block-menu" role="navigation">
  <div class="block-inner clearfix">
                <div class="block-content content">
      <ul class="menu clearfix"><li class="first expanded depth-1 menu-16919"><a style="cursor: pointer;">应用开发</a><ul class="menu clearfix"><li class="first leaf google-track-navigation depth-2 menu-16947"><a href="http://software.intel.com/zh-cn/windows">Windows*</a></li>
<li class="leaf google-track-navigation depth-2 menu-16954"><a href="http://software.intel.com/zh-cn/android">安卓*</a></li>
<li class="leaf google-track-navigation depth-2 menu-16961"><a href="http://software.intel.com/zh-cn/html5">HTML5</a></li>
<li class="leaf google-track-navigation depth-2 menu-16975"><a href="http://software.intel.com/zh-cn/cloud-services-platform">服务</a></li>
<li class="last leaf google-track-navigation depth-2 menu-16976"><a href="http://software.intel.com/zh-cn/intel-sdp-home">开发工具</a></li>
</ul></li>
<li class="expanded depth-1 menu-16926"><a style="cursor: pointer;">英特尔® 平台开发</a><ul class="menu clearfix"><li class="first leaf google-track-navigation depth-2 menu-16983"><a href="http://software.intel.com/zh-cn/windows">超极本™</a></li>
<li class="leaf google-track-navigation depth-2 menu-16990"><a href="http://software.intel.com/zh-cn/node/393420">平板电脑和手机</a></li>
<li class="leaf google-track-navigation depth-2 menu-16997"><a href="http://software.intel.com/zh-cn/embedded-development-tools">嵌入式系统</a></li>
<li class="leaf google-track-navigation depth-2 menu-17004"><a href="http://software.intel.com/zh-cn/business-client">企业客户端</a></li>
<li class="leaf google-track-navigation depth-2 menu-17011"><a href="http://software.intel.com/zh-cn/server-developer">服务器、工作站、高性能计算</a></li>
<li class="last leaf google-track-navigation depth-2 menu-17018"><a href="http://software.intel.com/zh-cn/intel-sdp-home">开发工具</a></li>
</ul></li>
<li class="expanded depth-1 menu-16933"><a style="cursor: pointer;">英特尔® 技术</a><ul style="min-width: 365px;" class="menu clearfix"><li style="float: left; width: 50%; clear: left;" class="first leaf google-track-navigation depth-2 menu-17025"><a href="http://software.intel.com/zh-cn/html5">HTML5</a></li>
<li style="float: left; width: 50%;" class="leaf google-track-navigation depth-2 menu-17032"><a href="http://software.intel.com/zh-cn/articles/ultrabook-touch-and-sensor-resources">触摸屏和传感器</a></li>
<li style="float: left; width: 50%; clear: left;" class="leaf google-track-navigation depth-2 menu-17039"><a href="http://software.intel.com/zh-cn/vcsource/tools/perceptual-computing-sdk">感知计算</a></li>
<li style="float: left; width: 50%;" class="leaf google-track-navigation depth-2 menu-17046"><a href="http://software.intel.com/zh-cn/vcsource">视觉计算</a></li>
<li style="float: left; width: 50%; clear: left;" class="leaf google-track-navigation depth-2 menu-17054"><a href="http://software.intel.com/zh-cn/energy-efficient-software">能源效率</a></li>
<li style="float: left; width: 50%;" class="leaf google-track-navigation depth-2 menu-17145"><a href="http://software.intel.com/zh-cn/node/47933">性能</a></li>
<li style="float: left; width: 50%; clear: left;" class="leaf google-track-navigation depth-2 menu-17067"><a href="http://software.intel.com/zh-cn/security">安全</a></li>
<li style="float: left; width: 50%;" class="leaf google-track-navigation depth-2 menu-17074"><a href="http://software.intel.com/zh-cn/oss">开源</a></li>
<li style="float: left; width: 50%; clear: left;" class="leaf google-track-navigation depth-2 menu-17081"><a href="http://software.intel.com/zh-cn/embedded-development-tools">系统设计</a></li>
<li style="float: left; width: 50%;" class="last leaf google-track-navigation depth-2 menu-17088"><a href="http://software.intel.com/zh-cn/intel-sdp-home">开发工具</a></li>
</ul></li>
<li class="last expanded depth-1 menu-16940"><a style="cursor: pointer;">业务资源</a><ul class="menu clearfix"><li class="first leaf google-track-navigation depth-2 menu-17102"><a href="http://software.intel.com/zh-cn/partner-home">英特尔® 软件合作伙伴</a></li>
<li class="leaf google-track-navigation depth-2 menu-17109"><a href="http://software.intel.com/zh-cn/success-stories">成功案例</a></li>
<li class="leaf google-track-navigation depth-2 menu-17199"><a href="http://software.intel.com/zh-cn/software-initiatives">按行业分类软件</a></li>
<li class="leaf google-track-navigation depth-2 menu-17116"><a href="http://software.intel.com/zh-cn/business-network">联系和协作</a></li>
<li class="leaf google-track-navigation depth-2 menu-17123"><a href="http://software.intel.com/zh-cn/appup">英特尔 AppUp® 开发人员</a></li>
<li class="last leaf google-track-navigation depth-2 menu-17130"><a href="http://software.intel.com/zh-cn/academic">学术</a></li>
</ul></li>
</ul>    </div>
  </div>
</nav>
<div id="block-idz-search-idz-search-block" class="block block-idz-search">
  <div class="block-inner clearfix">
                <div class="block-content content">
      <div class="container-inline">
  <form class="bootstrap" action="/zh-cn/blogs/2013/05/20/java-socket/?utm_campaign=CSDN&amp;utm_source=intel.csdn.net&amp;utm_medium=Link&amp;utm_content=others-%20java%20socket" method="post" id="idz-search-block-form" accept-charset="UTF-8"><div><div class="input-prepend input-append form-wrapper" id="idz_search_search_form"><a id="search-dropdown" type="submit" name="op" value="" class="form-submit btn dropdown-toggle" data-toggle="dropdown" data-target="#"><i class="icon-chevron-down"></i> </a><ul id="search-dropdown-options" class="dropdown-menu"><li class="disabled"><a href="#">Site to search:</a></li><li class="divider"></li><li><a class="active" href="#" value="idz">Intel® DZ</a></li><li><a href="#" value="intel">Intel.com</a></li></ul><input title="What can we help you find today?" placeholder="What can we help you find today?" class="form-text" id="edit-search-keyword" name="search_keyword" size="15" maxlength="128" type="text"><button class="btn form-submit btn dropdown-toggle" type="submit" id="edit-submit" name="op" value="搜索"><i class="icon-search"></i> </button></div><input name="form_build_id" value="form-a9Gt_Wx1Bpj1OX_XjCVCqBCsH1o9Enldc6LMMqg-qb0" type="hidden">
<input name="form_id" value="idz_search_block_form" type="hidden">
</div></form></div>

<div id="header-user-display">
      <span class="login">
      <a href="https://secure-software.intel.com/zh-cn/user/login?destination=node/392764%3Futm_campaign%3DCSDN%26utm_source%3Dintel.csdn.net%26utm_medium%3DLink%26utm_content%3Dothers-%2520java%2520socket">登录</a> | <a href="https://secure-software.intel.com/partner/app/registration/intro?destination=node/392764%3Futm_campaign%3DCSDN%26utm_source%3Dintel.csdn.net%26utm_medium%3DLink%26utm_content%3Dothers-%2520java%2520socket&amp;locale=zh-cn">注册</a>    </span>
  </div>
    </div>
  </div>
</div>
  </div>

  </header>

    
  <div id="before-content">
    <nav id="breadcrumb" class="has-content">
              <h2 class="element-invisible">你在这里</h2><div class="breadcrumb"><a href="http://software.intel.com/zh-cn">Home</a> › <a href="http://software.intel.com/zh-cn/search/site/?f[0]=bundle%3Ablog">Blogs</a> › java socket 多线程网络传输多个文件</div>          </nav>

    
          </div>

  <div id="columns"><div class="columns-inner clearfix">
    <div id="content-column"><div class="content-inner">

      
            <section id="main-content" role="main">

                
                  <header>
                          <h1 id="page-title">java socket 多线程网络传输多个文件</h1>
            
                      </header>
                        <div id="content">  <div class="region region-content">
    <div id="block-system-main" class="block block-system">
  <div class="block-inner clearfix">
                <div class="block-content content">
      <article id="article-392764" class="article article-type-blog clearfix" about="/zh-cn/blogs/2013/05/20/java-socket" typeof="sioc:Item foaf:Document" role="article">

  
      
      <footer class="submitted">
      <p class="author-datetime"><span property="dc:date dc:created" content="2013-05-20T05:03:03-07:00" datatype="xsd:dateTime" rel="sioc:has_creator"><a href="http://software.intel.com/zh-cn/user/817741" title="查看用户资料" class="username" xml:lang="" about="/zh-cn/user/817741" typeof="sioc:UserAccount" property="foaf:name" datatype="">單純_.。。﹖</a> 于 <time datetime="2013-05-20T05:03:03Z" pubdate="pubdate">星期一, 20/05/2013 - 05:03</time> 提交</span></p>
    </footer>
    <div class="article-content">
  
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
	<rdf:Description rdf:about="http://software.intel.com/zh-cn/blogs/2013/05/20/java-socket" dc:identifier="http://software.intel.com/zh-cn/blogs/2013/05/20/java-socket" dc:title="java socket 多线程网络传输多个文件" trackback:ping="http://software.intel.com/zh-cn/blogs/2013/05/20/java-socket/trackback" />
</rdf:RDF>
-->
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"> <p>&nbsp;
 &nbsp; &nbsp;由于需要研究了下用 java socket 
传输文件，由于需要传输多个文件，因此，采用了多线程设计。客户端每个线程创建一个 socket 连接，每个 socket 
连接负责传输一个文件，服务端的ServerSocket每次 accept 一个 socket 连接，创建一个线程用于接收客户端传来的文件。</p>
<p>1、服务端</p>
<p>&nbsp;&nbsp;&nbsp; import java.io.BufferedInputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.BufferedOutputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.DataInputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.DataOutputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.FileOutputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.net.ServerSocket; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.net.Socket; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.util.concurrent.ExecutorService; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.util.concurrent.Executors; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; public class TransferServer { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 private int defaultBindPort = 
Constants.DEFAULT_BIND_PORT;&nbsp;&nbsp;&nbsp; //默认监听端口号为10000 &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 private int tryBindTimes = 
0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
//初始的绑定端口的次数设定为0 &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 private ServerSocket serverSocket;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
//服务套接字等待对方的连接和文件发送 &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private ExecutorService executorService;&nbsp;&nbsp;&nbsp; //线程池 &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 private final int POOL_SIZE = 
4;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
//单个CPU的线程池大小&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /**&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 不带参数的构造器，选用默认的端口号&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public TransferServer() throws Exception{ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 this.bingToServerPort(defaultBindPort); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 executorService = 
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() *
 POOL_SIZE); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 System.out.println("开辟线程数 ： " + 
Runtime.getRuntime().availableProcessors() * POOL_SIZE); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 throw new Exception("绑定端口不成功!"); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /**&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 带参数的构造器，选用用户指定的端口号&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param port&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public TransferServer(int port) throws Exception{ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.bingToServerPort(port); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 executorService = 
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() *
 POOL_SIZE); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 throw new Exception("绑定端口不成功!"); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void bingToServerPort(int port) throws Exception{ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 serverSocket = new ServerSocket(port); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(port); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("服务启动!"); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 this.tryBindTimes = this.tryBindTimes + 1; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 port = port + this.tryBindTimes; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 if(this.tryBindTimes &gt;= 20){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 throw new Exception("您已经尝试很多次了，但是仍无法绑定到指定的端口!请重新选择绑定的默认端口号"); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //递归绑定端口 &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.bingToServerPort(port); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void service(){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Socket socket = null; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (true) { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 socket = serverSocket.accept(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 executorService.execute(new Handler(socket)); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 e.printStackTrace(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class Handler implements Runnable{ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private Socket socket; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Handler(Socket socket){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.socket = socket; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void run() { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 System.out.println("New connection accepted " + socket.getInetAddress()
 + ":" + socket.getPort()); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataInputStream dis = null; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataOutputStream dos = null; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int bufferSize = 8192; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 byte[] buf = new byte[bufferSize]; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 dis = new DataInputStream(new 
BufferedInputStream(socket.getInputStream())); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 String savePath = Constants.RECEIVE_FILE_PATH + dis.readUTF(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 long length = dis.readLong(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 dos = new DataOutputStream(new BufferedOutputStream(new 
FileOutputStream(savePath))); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 int read = 0; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 long passedlen = 0; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 while ((read = dis.read(buf)) != -1) { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 passedlen += read; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 dos.write(buf, 0, read); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 System.out.println("文件[" + savePath + "]已经接收: " + passedlen * 100L/ 
length + "%"); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 System.out.println("文件: " + savePath + "接收完成!"); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 e.printStackTrace(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Exception{ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new TransferServer().service(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;</p>
<p><br><br>2、客户端<br>&nbsp;&nbsp;&nbsp; import java.io.BufferedInputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.DataInputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.DataOutputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.File; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.io.FileInputStream; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.net.Socket; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.util.ArrayList; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.util.Random; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.util.Vector; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.util.concurrent.ExecutorService; &nbsp;<br>&nbsp;&nbsp;&nbsp; import java.util.concurrent.Executors; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; public class TransferClient { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 private static ArrayList&lt;String&gt; fileList = new 
ArrayList&lt;String&gt;(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private String sendFilePath = Constants.SEND_FILE_PATH; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /**&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 带参数的构造器，用户设定需要传送文件的文件夹&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param filePath&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public TransferClient(String filePath){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getFilePath(filePath); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /**&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 不带参数的构造器。使用默认的传送文件的文件夹&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public TransferClient(){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getFilePath(sendFilePath); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void service(){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 ExecutorService executorService = Executors.newCachedThreadPool(); 
&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Vector&lt;Integer&gt; vector = getRandom(fileList.size()); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(Integer integer : vector){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 String filePath = fileList.get(integer.intValue()); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 executorService.execute(sendFile(filePath)); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void getFilePath(String dirPath){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File dir = new File(dirPath); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File[] files = dir.listFiles(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(files == null){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int i = 0; i &lt; files.length; i++){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(files[i].isDirectory()){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 getFilePath(files[i].getAbsolutePath()); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 fileList.add(files[i].getAbsolutePath()); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private Vector&lt;Integer&gt; getRandom(int size){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vector&lt;Integer&gt; v = new Vector&lt;Integer&gt;(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Random r = new Random(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; boolean b = true; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(b){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i = r.nextInt(size); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!v.contains(i)) &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 v.add(i); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(v.size() == size) &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 b = false; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return v; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private static Runnable sendFile(final String filePath){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Runnable(){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private Socket socket = null; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 private String ip ="localhost"; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private int port = 10000; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void run() { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 System.out.println("开始发送文件:" + filePath); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 File file = new File(filePath); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 if(createConnection()){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 int bufferSize = 8192; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 byte[] buf = new byte[bufferSize]; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 try { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 DataInputStream fis = new DataInputStream(new BufferedInputStream(new 
FileInputStream(filePath))); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 passedlen += read; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 System.out.println("已经完成文件 [" + file.getName() + "]百分比: " + passedlen *
 100L/ length + "%"); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 dos.write(buf, 0, read); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 dos.flush(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void main(String[] args){ &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new TransferClient().service(); &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;<br>&nbsp;&nbsp;&nbsp; }</p>
<p></p>
<p>3、常量类</p>
<p>&nbsp;&nbsp;&nbsp; public interface Constants { &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public final static String RECEIVE_FILE_PATH = "E:\\receive\\"; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public final static String SEND_FILE_PATH = "E:\\send"; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public final static int DEFAULT_BIND_PORT = 10000; &nbsp;<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;pre name="code" id="best-content-1009763504" 
class="best-text mb-10" style="margin-top:0px; margin-bottom:10px; 
padding:0px; font-family:arial,'courier new',courier,宋体,monospace; 
white-space:pre-wrap; word-wrap:break-word; font-size:14px; 
line-height:24px; background-color:rgb(255,252,246)"&gt;&lt;/pre&gt; 
&nbsp;<br>&nbsp;&nbsp;&nbsp; &lt;pre&gt;&lt;/pre&gt; &nbsp;<br>&nbsp;&nbsp;&nbsp; &lt;pre&gt;&lt;/pre&gt; &nbsp;<br>&nbsp;&nbsp;&nbsp; &lt;pre&gt;&lt;/pre&gt;&nbsp;&nbsp;</p> </div></div></div><fieldset id="article-tags-wrap" class="form-wrapper"><div class="fieldset-wrapper">标签: <ul id="article-tags-wrap-list">
          <li class="field-item even">
        <a href="http://software.intel.com/zh-cn/tags/42835" typeof="skos:Concept" property="rdfs:label skos:prefLabel">java socket</a>      </li>
          <li class="field-item odd">
        <a href="http://software.intel.com/zh-cn/tags/33146" typeof="skos:Concept" property="rdfs:label skos:prefLabel">多线程</a>      </li>
      
</ul></div></fieldset>
  </div>

  
  
</article>    </div>
  </div>
</div>
  </div>
</div>
        
        <div class="optimization-notice">如需更全面地了解编译器优化，请参阅<a href="http://software.intel.com/zh-cn/articles/optimization-notice#opt-cn">优化注意事项</a>。</div>
                  <div id="button-links-wrap" class="clearfix"><div class="item-list"><ul class="links inline"><li class="comment"><a href="http://software.intel.com/zh-cn/user/login?destination=node/392764%23comment-form">登录</a>以发表评论</li></ul></div></div>
        
                  <div id="links-wrap" class="clearfix">
                          <div id="links"></div>
                                      <div class="rss-link"><a href="http://software.intel.com/zh-cn/blogs/392764/comments-feed">RSS</a></div>
                      </div>
                <div class="clearfix"></div>
                  <div id="comments"></div>
                               
      </section>

      
    </div></div>

        
  </div></div>

      <footer role="contentinfo">  <div class="region region-footer">
    <nav id="block-menu-menu-footer-block" class="block block-menu" role="navigation">
  <div class="block-inner clearfix">
                <div class="block-content content">
      <ul class="menu clearfix"><li class="first expanded depth-1 menu-15530">英特尔® 开发人员专区内容<ul class="menu clearfix"><li class="first leaf depth-2 menu-15532"><a href="http://software.intel.com/zh-cn/search/site">内容库</a></li>
<li class="leaf depth-2 menu-15533"><a href="http://software.intel.com/zh-cn/code-downloads">代码和下载</a></li>
<li class="leaf depth-2 menu-15531"><a href="http://software.intel.com/zh-cn/forum">论坛</a></li>
<li class="leaf depth-2 menu-16864"><a href="http://software.intel.com/zh-cn/blogs">博客</a></li>
<li class="last leaf depth-2 menu-16865"><a href="http://software.intel.com/zh-cn/videos">视频</a></li>
</ul></li>
<li class="expanded depth-1 menu-15526">软件资源<ul class="menu clearfix"><li class="first leaf depth-2 menu-15527"><a href="http://software.intel.com/zh-cn/blackbelt">英特尔® 黑带软件开发计划</a></li>
<li class="leaf depth-2 menu-15528"><a href="http://software.intel.com/zh-cn/partner-home">英特尔® 软件合作伙伴会员资格</a></li>
<li class="last leaf depth-2 menu-15529"><a href="http://software.intel.com/zh-cn/intel-sdp-home">英特尔® 软件开发产品</a></li>
</ul></li>
<li class="expanded depth-1 menu-15534">出版物<ul class="menu clearfix"><li class="first leaf depth-2 menu-15535"><a href="http://software.intel.com/sites/billboard/isa-magazine" target="_blank">《Intel® Software Adrenaline》杂志</a></li>
<li class="leaf depth-2 menu-15536"><a href="http://software.intel.com/zh-cn/intel-parallel-universe-magazine">《Intel® Parallel Universe》杂志</a></li>
<li class="last leaf depth-2 menu-15537"><a href="http://software.intel.com/zh-cn/intel-developer-zone-newsletter">英特尔® 开发人员专区新闻简报</a></li>
</ul></li>
<li class="last expanded depth-1 menu-15538">英特尔软件子公司<ul class="menu clearfix"><li class="first leaf depth-2 menu-15539"><a href="http://www.mcafee.com/cn/" target="_blank">McAfee</a></li>
<li class="leaf depth-2 menu-15540"><a href="http://www.havok.com/cn" target="_blank">Havok</a></li>
<li class="last leaf depth-2 menu-15541"><a href="http://www.windriver.com/" target="_blank">Wind River</a></li>
</ul></li>
</ul>    </div>
  </div>
</nav>
  </div>
</footer>
  </div>

  <div id="superfooter">  <div class="region region-superfooter">
    <nav id="block-menu-menu-superfooter" class="block block-menu" role="navigation">
  <div class="block-inner clearfix">
                <div class="block-content content">
      <ul class="menu clearfix"><li class="first leaf depth-1 menu-11785"><a href="http://www.intel.cn/" target="_blank">英特尔公司</a></li>
<li class="leaf depth-1 menu-11797"><a href="http://software.intel.com/zh-cn/contact">英特尔® 开发人员专区支持</a></li>
<li class="leaf depth-1 menu-11804"><a href="http://software.intel.com/zh-cn/faq" target="_blank">常见问题解答</a></li>
<li class="leaf depth-1 menu-11818"><a href="http://www.intel.cn/content/www/cn/zh/legal/terms-of-use.html" target="_blank">使用条款</a></li>
<li class="leaf depth-1 menu-11825"><a href="http://www.intel.cn/content/www/cn/zh/legal/trademarks.html" target="_blank">*商标</a></li>
<li class="leaf depth-1 menu-11838"><a href="http://www.intel.cn/content/www/cn/zh/privacy/intel-online-privacy-notice-summary.html" target="_blank">隐私条款</a></li>
<li class="last leaf depth-1 menu-16698"><a href="http://www.intel.cn/content/www/cn/zh/privacy/intel-cookie-notice.html" target="_blank">Cookie</a></li>
</ul>    </div>
  </div>
</nav>
  </div>
</div>

  <div id="language-superfooter">  <div class="region region-language-superfooter">
    <div id="block-locale-language" class="block block-locale isn3_footer-processed" role="complementary">
  <div class="block-inner clearfix">
                <div class="block-content content">
      <ul class="language-switcher-locale-url"><li><a href="http://software.intel.com/zh-cn/blogs/2013/05/20/java-socket" class="language-link active" lang="zh-hans">简体中文</a><ul style="display: none;" id="idz-js-lang-popup"><li class="close-btn">X</li><li><a href="http://software.intel.com/en-us/node/392764" class="language-link locale-untranslated" rel="nofollow" lang="en">English</a></li><li><a href="http://software.intel.com/fr-fr/node/392764" class="language-link locale-untranslated" rel="nofollow" lang="fr">Français</a></li><li><a href="http://software.intel.com/ru-ru/node/392764" class="language-link locale-untranslated" rel="nofollow" lang="ru">Русский</a></li><li><a href="http://software.intel.com/es-es/node/392764" class="language-link locale-untranslated" rel="nofollow" lang="es">Español</a></li><li><a href="http://software.intel.com/pt-br/node/392764" class="language-link locale-untranslated" rel="nofollow" lang="pt-br">Português</a></li><li><a href="http://software.intel.com/de-de/node/392764" class="language-link locale-untranslated" rel="nofollow" lang="de">Deutsch</a></li><li><a href="http://software.intel.com/it-it/node/392764" class="language-link locale-untranslated" rel="nofollow" lang="it">Italiano</a></li></ul></li></ul>    </div>
  </div>
</div>
  </div>
</div>
  <script src="java%20socket%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E7%BD%91%E7%BB%9C%E4%BC%A0%E8%BE%93%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%20_%20Intel%C2%AE%20Developer%20Zone_files/js_Ib3CK8V4Zej3VBgJqfHptuP3qECU_jYupj-T6qrzny0.js"></script>


<div style="display: none;" id="cboxOverlay"></div><div style="display: none; padding-bottom: 50px; padding-right: 50px;" class="" id="colorbox"><div id="cboxWrapper"><div><div style="float: left;" id="cboxTopLeft"></div><div style="float: left;" id="cboxTopCenter"></div><div style="float: left;" id="cboxTopRight"></div></div><div style="clear: left;"><div style="float: left;" id="cboxMiddleLeft"></div><div style="float: left;" id="cboxContent"><div style="width: 0px; height: 0px; overflow: hidden; float: left;" id="cboxLoadedContent"></div><div style="float: left;" id="cboxLoadingOverlay"></div><div style="float: left;" id="cboxLoadingGraphic"></div><div style="float: left;" id="cboxTitle"></div><div style="float: left;" id="cboxCurrent"></div><div style="float: left;" id="cboxNext"></div><div style="float: left;" id="cboxPrevious"></div><div style="float: left;" id="cboxSlideshow"></div><div style="float: left;" id="cboxClose"></div></div><div style="float: left;" id="cboxMiddleRight"></div></div><div style="clear: left;"><div style="float: left;" id="cboxBottomLeft"></div><div style="float: left;" id="cboxBottomCenter"></div><div style="float: left;" id="cboxBottomRight"></div></div></div><div style="position: absolute; width: 9999px; visibility: hidden; display: none;"></div></div></body></html>